package cn.iocoder.devlop.module.annual.report.websiteinfo.controller.app;

import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.module.annual.report.websiteinfo.controller.vo.WebsiteinfoOverwriteVO;
import cn.iocoder.devlop.module.annual.report.websiteinfo.controller.vo.WebsiteinfoRespVO;
import cn.iocoder.devlop.module.annual.report.websiteinfo.convert.WebsiteinfoConvert;
import cn.iocoder.devlop.module.annual.report.websiteinfo.dal.dataobject.WebsiteinfoDO;
import cn.iocoder.devlop.module.annual.report.websiteinfo.service.WebsiteinfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 企业年报网站或网店信息")
@RestController
@RequestMapping("/annual/report/websiteinfo")
@Validated
public class AppWebsiteinfoController {

    @Resource
    private WebsiteinfoService websiteinfoService;


    @GetMapping("/list")
    @Operation(summary = "获得企业年报网站或网店信息列表")
    public CommonResult<List<WebsiteinfoRespVO>> getWebsiteinfoList(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        List<WebsiteinfoDO> websiteinfos = websiteinfoService.getWebsiteinfoList(regno, ancheyear);
        return success(WebsiteinfoConvert.INSTANCE.convertList(websiteinfos));
    }

    @PutMapping("/overwrite")
    @Operation(summary = "覆盖更新企业年报网站或网店信息")
    public CommonResult<Boolean> overwriteWebsiteinfo(@Valid @RequestBody WebsiteinfoOverwriteVO updateReqVO) {
        websiteinfoService.overwriteWebsiteinfo(updateReqVO);
        return success(true);
    }


}
